package com.kfm.am;

import java.util.Arrays;
import java.util.Random;

public class Exec02 {

    public static void main(String[] args) {
        // 随机生成 20 个 1~ 40 之间的不重复幸运数字存储到数组中。
        // 要求: 数组中的数字乱序
        int[] arr = randArr();
        System.out.println(Arrays.toString(arr));
//        for (int i = 0; i < arr.length; i++) {
//            System.out.println(arr[i]);
//        }
    }

    public static int[] randArr() {
        int[] arr = new int[20];
        Random random = new Random();
        int count = 0;
        while (count < 20) {
            int number = random.nextInt(40) + 1;
            if (hasNumber(arr, number, count)) {
                arr[count ++] = number;
            }
        }
        return arr;
    }

    public static boolean hasNumber(int[] arr, int number, int count) {
        for (int i = 0; i < count; i++) {
            if (arr[i] == number) {
                return false;
            }
        }
        return true;
    }
}
